// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js'ionic-native-transitions'
angular.module('starter',
  ['ionic','ngCordova','tabSlideBox',
    'ngResource','flexcalendar','starter.commonService',
    'starter.config','starter.router','starter.directive','ngIOS9UIWebViewPatch',
    'logincontrollers','newscontrollers','newsdetailcontrollers','newsmorecontrollers','newsseachcontrollers',
    'videoservice','videocontrollers','bookshelfcontrollers','videomorecontrollers',
    'magazinectroller','magazineservice','bookshelfsearchcontrollers',
    'loginservices','newsservices',
    "my-integrat-controller","my-integrat-service",
    'wineIndexcontrollers','wineservices','winedetailcontrollers',
    'meetingservice','meetingcontrollers','releasemeetingcontrollers',
    'msgboxservice','msgboxcontrollers','myactivitycontrollers',
	  'meetingdetailcontrollers','calendarcontrollers','enrolllistcontrollers',
    'enrollfromcontrollers', 'dayactivitycontrollers',
    'shopdetailcontrollers','shopdetailservice','discovermemberservice',//发现会员列表
    'meattendcontrollers','meattendservice','searchfriendcontrollers',//我---->我关注
    'mecollectcontrollers','mecollectservice',//我------>我的收藏
    'homeservice','releasehomecontrollers','otheruserhomecontrollers',
    'userhomeservice',//酒窝
    'mehomecontrollers',//我的酒窝
    'lbscontrollers','lbsService',//Lbs定位
    'calendarservices',
	  'meindexservices','meindexcontrollers',
    'memydataservices','memydatacontrollers',
    'revisepasswordcontrollers','meRevisePasswordServices',
    'meMyLevelcontrollers','meMyLevelServices',
    'meMyIntegratDetailControllers','meMyIntegratDetailServices',
    'meIntegratListControllers','meIntegratListServices',
    'meConvertedMsgControllers','meConvertedMsgServices',
    'meMoreListControllers','meMoreListServices',
    'meMoreAboutUsControllers','meMoreAboutUsServices',
    'meMoreCooperateControllers','meMoreCooperateServices',
    'meMoreRuleControllers','meMoreRuleServices',
    'meMoreOpinionaireControllers','meMoreOpinionaireServices',
    'meRecommendListcontrollers','meRecommendListservices',
    'meRecommendOrderListcontrollers','meRecommendOrderListservices',
    'meHistoryListcontrollers','meHistoryListservices',
    'meHistoryOrderDetailcontrollers','meHistoryOrderDetailservices',
    'meHistoryOrderDelcontrollers','meHistoryOrderDelservices',
    'meBindMemberControllers','meBindMemberServices',
    'meBindingControllers','meBindingServices',
    'mePointProductMsgControllers','mePointProductMsgServices',
    'shareservice','shareserviceother'
    ])
.run(function($rootScope,$http,$cordovaAppVersion,$ionicPopup,$ionicPlatform,$cordovaSplashscreen,$cordovaStatusbar,$ionicLoading,$state,$timeout,$ionicHistory,Toast,ENV) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
      // $cordovaStatusbar.style(1);
    }
    //隐藏启动页
    $timeout(function(){
      $cordovaSplashscreen.hide();
    },500);
    //检测版本更新
    if(ionic.Platform.isAndroid()){
      checkUpdate();
    }

    /***双击退出开始**/
      // 双击退出
    $ionicPlatform.registerBackButtonAction(function (e) {
        $ionicLoading.hide();
      //如果是在发现首页和登录页面的话
      if($rootScope.gallery){
        $rootScope.gallery.close();
        $rootScope.gallery ='';
        $cordovaStatusbar.show();
      }else if ($state.includes('tab.discoverIndex')||$state.includes('login')) {
        if ($rootScope.backButtonPressedOnceToExit) {
          ionic.Platform.exitApp();
        } else {
          $rootScope.backButtonPressedOnceToExit = true;
          Toast.showMessage('再按一次退出程序');
          setTimeout(function () {
            $rootScope.backButtonPressedOnceToExit = false;
          }, 2000);
        }
        //如果页面在资讯，我的，书架首页的时候
      } else if ($state.includes('tab.bookshelfIndex') || $state.includes('tab.meIndex')|| $state.includes('tab.newsIndex')) {
        $state.go('tab.discoverIndex');
      }
      else if ($ionicHistory.backView()) {
        $ionicHistory.goBack();
      } else {
        if ($rootScope.backButtonPressedOnceToExit) {
          ionic.Platform.exitApp();
        }
        $rootScope.backButtonPressedOnceToExit = true;
        Toast.showMessage('再按一次退出程序');
        setTimeout(function () {
          $rootScope.backButtonPressedOnceToExit = false;
        }, 2000);
      }
      e.preventDefault();
      return false;
    }, 101);
    /*******双击退出结束******/
  });

    //检测版本更新
    /*checkUpdate = function(){
      $http({
        url:ENV.updatePath,
        method:'GET',
        cache:false
      }).success(function(appVersion){
        $cordovaAppVersion.getVersionNumber().then(function (version) {
          //如果本地与服务端的APP版本不符合
          if (version != appVersion.version) {
            $ionicPopup.confirm({
              title: '版本升级',
              template: '<p style="text-align: center;font-size:16px;">是否升级到最新版本？</p>',
              cancelText: '取消',
              okText: '确定',
              okType: 'hd-red-btn',
              cancelType: 'cancel-esc-btn'
            }).then(function (res) {
              if (res) {
                cordova.ThemeableBrowser.open(appVersion.downloadPath, '_system',{});
              }
            });
          }
        });
      }).error(function(data){
      });
    }*/
});



